﻿@model AddTempProductModel

@{
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@{
    var viewModel = Model ?? new AddTempProductModel();
}
<form id="S_Form" action="@Url.Action("addTempProduct", "TempProduct")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" width="50%">
                <h5>
                    @ViewBag.Title，请输入物料信息，标<em>*</em>号是必填或必选项。
                </h5>
                <input type="hidden" value="@viewModel.aDZ_GoodsTemp.seq_id" name="aDZ_GoodsTemp.seq_id" />
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">品牌<em>*</em></td>
            <td>
                <div id="brand_name"></div>
                @*<input type="text" id="aDZ_BrandMaster.brand_name" name="aDZ_BrandMaster.brand_name" maxlength="50" value="@viewModel.aDZ_BrandMaster.brand_name" />*@
            </td>

            <td class="tableleft">分类<em>*</em></td>
            <td>
                <div id="category_name"></div>
                @*<input type="text" id="aDZ_GoodsCategory.category_name" name="aDZ_GoodsCategory.category_name" maxlength="50" value="@viewModel.aDZ_GoodsCategory.category_name" />*@
            </td>
        </tr>
        <tr id="Tr_AgainPwd">
            <td class="tableleft">供应商<em>*</em></td>
            <td>
                <div id="supplier_name"></div>
                @*<input type="text" id="aDZ_SupplierMaster.supplier_name" name="aDZ_SupplierMaster.supplier_name" maxlength="50" value="@viewModel.aDZ_SupplierMaster.supplier_name" />*@
            </td>

            <td class="tableleft">板块<em>*</em></td>
            <td>
                @{
                    var labeldic = ReleaseBiz.GetLabelTypeNameDic();
                    foreach (var item in labeldic)
                    {
                        <input type="radio" name="aDZ_GoodsLabel.label_type" style="vertical-align:middle; margin-bottom:6px;" value="@item.Key" @(viewModel.aDZ_GoodsLabel.label_type == byte.Parse(item.Key) ? "checked" : "") />@item.Value
                    }
                }

                <info id="business_info">
                    <br />
                    <info>
                        业务编号：<input type="text" name="goodsBusinessModel.business_id" maxlength="50" value="@viewModel.goodsBusinessModel.business_id" />（竞价和活动才需要填此编号）
                    </info>
                </info>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">物料来源<em>*</em></td>
            <td colspan="3">
                <div id="material_source"></div>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">料号<em>*</em></td>
            <td><input type="text" name="aDZ_GoodsMaster.MPN" maxlength="50" value="@viewModel.aDZ_GoodsMaster.MPN" /></td>
            <td class="tableleft">结束时间<em></em></td>

            <td>
                <input type="text" name="aDZ_GoodsLabel.end_time" class="calendar calendar-time" maxlength="50" value="@viewModel.aDZ_GoodsLabel.end_time.ToString(1)" />
            </td>
        </tr>
        <tr>
            <td class="tableleft">售卖单位<em>*</em></td>
            <td>
                <input type="radio" name="aDZ_GoodsMaster.goods_unit" style="vertical-align:middle; margin-bottom:6px;" value="K" />K
                <input type="radio" name="aDZ_GoodsMaster.goods_unit" style="vertical-align:middle; margin-bottom:6px;" value="PCS" />PCS
            </td>
            <td class="tableleft">DC号<em>*</em></td>
            <td><input type="text" name="aDZ_GoodsMaster.DCN" maxlength="50" value="@viewModel.aDZ_GoodsMaster.DCN" /></td>
        </tr>
        <tr>
            <td class="tableleft">库存数量<em>*</em></td>
            <td><input type="text" name="aDZ_GoodsMaster.stock_amount" maxlength="50" value="@viewModel.aDZ_GoodsMaster.stock_amount" /> <info class="goods_unit">@viewModel.aDZ_GoodsMaster.goods_unit</info></td>
            <td class="tableleft">最小订购量<em>*</em></td>
            <td><input type="text" name="aDZ_GoodsMaster.min_amount" maxlength="50" value="@viewModel.aDZ_GoodsMaster.min_amount" /> <info class="goods_unit">@viewModel.aDZ_GoodsMaster.goods_unit</info></td>
        </tr>
        <tr>
            <td class="tableleft">上传价格</td>
            <td>
                <input type="text" name="aDZ_GoodsMaster.price" maxlength="50" value="@viewModel.aDZ_GoodsMaster.price" />
                <input type="radio" name="aDZ_GoodsMaster.currency_type" style="vertical-align:middle; margin-bottom:6px;" value="0" />人民币/<info class="goods_unit">@viewModel.aDZ_GoodsMaster.goods_unit</info>
                <input type="radio" name="aDZ_GoodsMaster.currency_type" style="vertical-align:middle; margin-bottom:6px;" value="1" />美金/<info class="goods_unit">@viewModel.aDZ_GoodsMaster.goods_unit</info>

            </td>

            <td class="tableleft">是否含税<em>*</em></td>
            <td>
                <input type="radio" name="aDZ_GoodsMaster.include_tax" style="vertical-align:middle; margin-bottom:6px;" value="0" />未含税
                <input type="radio" name="aDZ_GoodsMaster.include_tax" style="vertical-align:middle; margin-bottom:6px;" value="1" />含税
            </td>
        </tr>
        <tr>
            <td class="tableleft">市场价格</td>
            <td><input type="text" name="aDZ_GoodsMaster.market_price" maxlength="50" value="@viewModel.aDZ_GoodsMaster.market_price" /> （<info class="goods_unit">@viewModel.aDZ_GoodsMaster.goods_unit</info>）</td>
            <td class="tableleft">普通会员可看(默认不可看)</td>
            <td>
                <input type="radio" name="aDZ_GoodsLabel.show_min_level" style="vertical-align:middle; margin-bottom:6px;" value="0" />可看
                <input type="radio" name="aDZ_GoodsLabel.show_min_level" style="vertical-align:middle; margin-bottom:6px;" value="1" />不可看
            </td>
        </tr>
        <tr>
            <td>供货价</td>
            <td colspan="2"><input type="text" name="aDZ_GoodsMaster.supply_price" maxlength="50" value="@viewModel.aDZ_GoodsMaster.supply_price" /> （<info class="goods_unit">@viewModel.aDZ_GoodsMaster.goods_unit</info>）</td>
        </tr>
        <tr>
            <td class="tableleft">商品描述</td>
            <td><textarea name="aDZ_GoodsMaster.product_desc" style="width:80%;" maxlength="2500" cols="4">@viewModel.aDZ_GoodsMaster.product_desc</textarea></td>

            <td class="tableleft">备注</td>
            <td><textarea name="aDZ_GoodsTemp.remark" style="width:80%;" maxlength="250" cols="4">@viewModel.aDZ_GoodsTemp.remark</textarea></td>
        </tr>
        <tr>
            <td class="tableleft">商品图片</td>
            <td colspan="3">
                @{
                    //构建默认对象
                    var imglist = viewModel.aDZ_GoodsIMGs.OrderBy(t => t.sort_NO).ToList();
                }
                @{Html.RenderPartial(Url.Content("~/Views/Common/Imgs.cshtml"), imglist);}
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p><span id="spMsg"></span></p>
                <button type="submit" class="btn btn-primary">保存</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>

        </tr>
    </table>
    <script type="text/javascript">
        BUI.use('bui/select', function (Select) {
            var b = '@viewModel.aDZ_BrandMaster.brand_name';
            var s = '@viewModel.aDZ_SupplierMaster.supplier_name';
            var c = '@viewModel.aDZ_GoodsCategory.category_name';
            var d = '@viewModel.aDZ_MaterialSource.supplier_name';

            $.post('@Url.Action("getselect", "common")', { selectType: 2 }, function (result) {
                var suggest = new Select.Suggest({
                    render: '#brand_name',
                    name: 'aDZ_BrandMaster.brand_name',
                    data: result
                });
                suggest.render();
                $("input[name='aDZ_BrandMaster.brand_name']").val(b);
                $("input[name='aDZ_BrandMaster.brand_name']").attr("autocomplete", "off");
            });

            $.post('@Url.Action("getselect", "common")', { selectType: 3 }, function (result) {
                var suggest = new Select.Suggest({
                    render: '#category_name',
                    name: 'aDZ_GoodsCategory.category_name',
                    data: result
                });
                suggest.render();
                $("input[name='aDZ_GoodsCategory.category_name']").val(c);
                $("input[name='aDZ_GoodsCategory.category_name']").attr("autocomplete", "off");
            });

            $.post('@Url.Action("getselect", "common")', { selectType: 1 }, function (result) {
                var suggest = new Select.Suggest({
                    render: '#supplier_name',
                    name: 'aDZ_SupplierMaster.supplier_name',
                    data: result
                });
                suggest.render();
                $("input[name='aDZ_SupplierMaster.supplier_name']").val(s);
                $("input[name='aDZ_SupplierMaster.supplier_name']").attr("autocomplete", "off");
            });

            $.post('@Url.Action("getselect", "common")', { selectType: 1 }, function (result) {
                var suggest = new Select.Suggest({
                    render: '#material_source',
                    name: 'aDZ_MaterialSource.supplier_name',
                    data: result
                });
                suggest.render();
                $("input[name='aDZ_MaterialSource.supplier_name']").val(d);
                $("input[name='aDZ_MaterialSource.supplier_name']").attr("autocomplete", "off");
            });
        });

        BUI.use('bui/overlay', function (overlay) {
            $(function () {
                //绑定信息
                switch ('@viewModel.aDZ_GoodsMaster.goods_unit') {
                    case 'K':
                        $("input[name='aDZ_GoodsMaster.goods_unit']").get(0).checked = true;
                        break;
                    case 'PCS':
                        $("input[name='aDZ_GoodsMaster.goods_unit']").get(1).checked = true;
                        break;
                }
                switch ('@viewModel.aDZ_GoodsMaster.currency_type') {
                    case '0':
                        $("input[name='aDZ_GoodsMaster.currency_type']").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name='aDZ_GoodsMaster.currency_type']").get(1).checked = true;
                        break;
                }
                switch ('@viewModel.aDZ_GoodsLabel.show_min_level') {
                    case '0':
                        $("input[name='aDZ_GoodsLabel.show_min_level']").get(0).checked = true;
                        break;
                    default:
                        $("input[name='aDZ_GoodsLabel.show_min_level']").get(1).checked = true;
                        break;
                }
                switch ('@viewModel.aDZ_GoodsMaster.include_tax') {
                    case '0':
                        $("input[name='aDZ_GoodsMaster.include_tax']").get(0).checked = true;
                        break;
                    default:
                        $("input[name='aDZ_GoodsMaster.include_tax']").get(1).checked = true;
                        break;
                }

                var rules = {
                    'aDZ_GoodsIMG_index': { required: true },
                    'aDZ_GoodsMaster.DCN': { required: true },
                    'aDZ_GoodsMaster.stock_amount': { required: true, IsNumber: true },
                    'aDZ_GoodsMaster.goods_unit': { required: true },
                    'aDZ_GoodsLabel.label_type': { required: true },
                    'aDZ_BrandMaster.brand_name': { required: true },
                    'aDZ_SupplierMaster.supplier_name': { required: true },
                    'aDZ_MaterialSource.supplier_name': { required: true },
                    'aDZ_GoodsMaster.MPN': { required: true },
                    'aDZ_GoodsCategory.category_name': { required: true },
                    'aDZ_GoodsMaster.min_amount': { required: true, IsNumber: true },
                    'aDZ_GoodsMaster.price': { IsNumber: true },
                    'aDZ_GoodsMaster.market_price': { IsNumber: true },
                    'aDZ_GoodsMaster.include_tax': { required: true },
                    'aDZ_GoodsMaster.commission_rate': { IsNumber: true },
                    'aDZ_GoodsMaster.currency_type': { required: true }
                };
                var messages = {
                    //'aDZ_GoodsMaster.goods_unit': { required: '售卖单位必选' },
                };

                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: rules,
                    messages: messages,
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            ShowActionResult(result, function () { self.location = document.referrer; });
                        });
                    }
                });

            });
        });

        $("input[name='aDZ_GoodsMaster.goods_unit']").click(function () {
            $(".goods_unit").html($(this).val());
        });

    </script>
</form>
